package com.yanqu.road.server.cmd.banquet.party;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.banquet.CrossPartyRelationship;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.banquet.BanquetRelationshipMgr;
import com.yanqu.road.server.pb.BanquetPb;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Cmd(code = Protocol.S_BANQUET_MEMBER_RELATIONSHIP, desc = "宴会成员互宴信息列表")
public class PartyMemberRelationshipCmd extends AbstractCommand {
    private int type;
    private List<Long> memberList;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BanquetProto.BanquetMemberRelationshipReqMsg reqMsg = BanquetProto.BanquetMemberRelationshipReqMsg.parseFrom(packet.getBytes());
        type = reqMsg.getType();
        memberList = reqMsg.getMemberIdListList();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        Map<Long, CrossPartyRelationship> recordMap = null;
        if(1 == type){
            recordMap = BanquetRelationshipMgr.getBanquetMemberRelationship(player.getUserId(),1,0, memberList);
        }else if(2 == type){
            ActivityInfo crbAcInfo = NormalActivityMgr.getRunningCrossBanquetRankActivity();
            //必须是跨服争霸，就是三个区服的才能开宴会
            if(null != crbAcInfo && crbAcInfo.getServerIdList().size() > 2){
                recordMap = BanquetRelationshipMgr.getBanquetMemberRelationship(player.getUserId(), 2, crbAcInfo.getBeginTime() * 1000,
                        memberList);
            }
        }
        List<CrossPartyRelationship> recordList;
        if(null == recordMap){
            recordList = new ArrayList<>();
        }else {
            recordList = new ArrayList<>(recordMap.values());
        }
        BanquetProto.BanquetRelationshipRespMsg.Builder respMsg = BanquetPb.parseCrossBanquetRelationshipRespMsg(recordList);
        player.sendPacket(Protocol.U_BANQUET_MEMBER_RELATIONSHIP, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
